/**
 * @date 2006-2-23 16:19:16
 *
 */
package org.nanhill.moo.domain.permission;

import java.util.HashSet;
import java.util.Set;

/**
 * 
 * @author alin [xalinx at gmail dot com]
 * 
 */
public abstract class Role {
	private long id;

	/**
	 * Role name.
	 */
	private String name;

	public String getName() {
		return name;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.nanhill.moo.domain.operation.permission.role.Role#setName(java.lang.String)
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * Role permissions.
	 */
	private Set<Permission> permissions;

	public Set<Permission> getPermissions() {
		return permissions;
	}

	public void setPermissions(Set<Permission> permissions) {
		this.permissions = permissions;
	}

	public void addPermission(Permission permission) {
		if (null == this.permissions) {
			this.permissions = new HashSet<Permission>();
		}
		this.permissions.add(permission);
	}

	@Override
	public boolean equals(Object other) {
		if (other == this)
			return true;
		if (!(other instanceof Role))
			return false;
		final Role per = (Role) other;
		return this.name.equals(per.getName());
	}

	@Override
	public int hashCode() {
		return name.hashCode();
	}

	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

}
